<?php
/**
 * @var \yii\web\View $this
 * @var \common\models\db\User $user
 */
use yii\helpers\Html;
use kartik\detail\DetailView;
use yii\helpers\Url;
use igorvolnyi\widgets\modal\ModalAjaxMultiple;
use wodrow\yii2wtools\tools\JsBlock;
use common\Tools;
use wodrow\yii2wtools\tools\ArrayHelper;
use fztadmin\modules\user\widgets\index_show_bank_cards\IndexShowBankCards;

$user = Yii::$app->user->identity;
$custom = $user->custom;
$fzt = Yii::$app->fenZhangTong;

$this->title = "分账通可视化后台首页";
?>

<div id="app">
    <div class="row">
        <div class="col-sm-3">
            <?= DetailView::widget([
                'model' => $user,
                'panel'=>[
                    'heading'=>"后台登录用户信息",
                    'type'=>DetailView::TYPE_DEFAULT,
                ],
                'enableEditMode' => false,
                'mode'=>DetailView::MODE_VIEW,
                'labelColOptions' => ['style' => 'max-width: 40%'],
                'attributes' => [
                    [
                        'attribute' => "avatar",
                        'label' => "头像",
                        'format' => "raw",
                        'value' => function ()use($user){
                            $html = Html::img($user->avatar, ['class' => "img img-responsive", 'style' => [
                                'height' => "50px;"
                            ]]);
                            return $html;
                        },
                    ],
                    [
                        'label' => "角色",
                        'format' => "raw",
                        'value' => function ()use($user){
                            $html = ArrayHelper::arr2str($user->getAdminRoleNames());
                            return $html;
                        },
                    ],
                    [
                        'attribute' => "username",
                        'value' => function ()use($user){
                            $html = "{$user->username}";
                            if ($user->is_admin_super) {
                                $html .= " <span class='text-danger'>超级管理员</span>";
                            }
                            return $html;
                        },
                        'format' => "raw",
                    ],
                    [
                        'attribute' => "nickname",
                    ],
                    [
                        'attribute' => "phone",
                        'label' => "手机号",
                        'format' => "raw",
                    ],
                    [
                        'label' => "邮箱",
                        'value' => function ()use($user){
                            $html = "{$user->email}";
                            return $html;
                        },
                        'format' => "raw",
                    ],
                    [
                        'label' => "添加时间",
                        'value' => date("Y-m-d H:i", $user->created_at),
                    ],
                    [
                        'label' => "其他",
                        'value' => function ()use($custom){
                            $html = ModalAjaxMultiple::widget([
                                    'header' => '修改密码',
                                    'toggleButton' => [
                                        'label' => '修改密码',
                                        'class' => 'btn btn-xs btn-warning'
                                    ],
                                    'url' => Url::to(['/user/center/update-password']), // Ajax view with form to load
                                    'ajaxSubmit' => true, // Submit the contained form as ajax, true by default
                                    'options' => ['class' => 'header-primary'],
                                    'autoClose' => true,
                                ]);
                            return $html;
                        },
                        'format' => "raw",
                    ],
                ],
            ]) ?>
        </div>
        <div class="col-sm-4">
            <?= DetailView::widget([
                'model' => $fzt,
                'panel'=>[
                    'heading'=>"平台信息",
                    'type'=>DetailView::TYPE_DEFAULT,
                ],
                'enableEditMode' => false,
                'mode'=>DetailView::MODE_VIEW,
                'labelColOptions' => ['style' => 'max-width: 40%'],
                'attributes' => [
                    [
                        'label' => "平台号",
                        'format' => "raw",
                        'value' => function ()use($fzt, $user){
                            $html = $user->is_admin_super ? $fzt->platNo : "你没有查看权限";
                            return $html;
                        },
                    ],
                    [
                        'label' => "对接版本",
                        'format' => "raw",
                        'value' => function ()use($fzt, $user){
                            $html = $fzt->version;
                            return $html;
                        },
                    ],
                    [
                        'label' => "余额信息",
                        'format' => "raw",
                        'value' => function ()use($fzt, $user){
                            $modalA = ModalAjaxMultiple::widget([
                                'header' => '查看余额信息',
                                'size' => ModalAjaxMultiple::SIZE_LARGE,
                                'toggleButton' => [
                                    'label' => '余额信息',
                                    'class' => 'btn btn-xs btn-primary'
                                ],
                                'url' => Url::to(['/ajax/plat/money-inquiry']), // Ajax view with form to load
                                'ajaxSubmit' => true, // Submit the contained form as ajax, true by default
                                'options' => ['class' => 'header-primary'],
                                'autoClose' => true,
                            ]);
                            $html = $user->is_admin_super ? $modalA : "你没有查看权限";
                            return $html;
                        },
                    ],
                ],
            ]) ?>
        </div>
        <div class="col-sm-5">
            <?php if($custom): ?>
                <?= DetailView::widget([
                    'model' => $custom,
                    'panel'=>[
                        'heading'=>"分账通客户信息",
                        'type'=>DetailView::TYPE_DEFAULT,
                    ],
                    'enableEditMode' => false,
                    'mode'=>DetailView::MODE_VIEW,
                    'labelColOptions' => ['style' => 'max-width: 40%'],
                    'attributes' => [
                        [
                            'label' => "客户编号",
                            'value' => function ()use($custom){
                                if ($custom->plat_cust_no) {
                                    $html = "{$custom->plat_cust_no}";
                                }else{
                                    $html = Html::tag('span', "本系统丢失了客户编号，你可以联系工作人员找回客户编号", ['class' => "text-warning"]);
                                }
                                return $html;
                            },
                            'format' => "raw",
                        ],
                        [
                            'label' => "手机号",
                            'format' => "raw",
                            'value' => function ()use($custom){
                                $html = "{$custom->mobile_no}";
                                $html .= " ".Html::a("修改手机号码", ['/user/center/update-mobile', 'custom_id' => $custom->id], ['class' => "btn btn-xs btn-info"]);
                                return $html;
                            },
                        ],
                        [
                            'label' => "邮箱",
                            'value' => function ()use($custom){
                                $html = "{$custom->email}";
                                return $html;
                            },
                            'format' => "raw",
                        ],
                        [
                            'label' => "姓名",
                            'value' => function ()use($custom){
                                $html = "{$custom->cust_name}";
                                return $html;
                            },
                            'format' => "raw",
                        ],
                        [
                            'label' => "证件类型",
                            'value' => function ()use($custom){
                                $html = $custom->getIdTypeDesc()[$custom->id_type];
                                return $html;
                            },
                            'format' => "raw",
                        ],
                        [
                            'label' => "证件号",
                            'value' => function ()use($custom){
                                $html = "{$custom->id_no}";
                                return $html;
                            },
                            'format' => "raw",
                        ],
//                        [
//                            'label' => "开户行",
//                            'value' => function ()use($custom, $fzt){
//                                $html = "[{$custom->open_bank}] {$fzt->getBankCodeNameMap()[$custom->open_bank]}";
//                                return $html;
//                            },
//                            'format' => "raw",
//                        ],
                        [
                            'label' => "银行卡",
                            'value' => function ()use($custom){
                                $html = "";
                                $html .= IndexShowBankCards::widget(['custom' => $custom]);
                                return $html;
                            },
                            'format' => "raw",
                        ],
                        [
                            'label' => "余额信息",
                            'format' => "raw",
                            'value' => function ()use($custom){
                                $modalA = ModalAjaxMultiple::widget([
                                    'header' => '查看余额信息',
                                    'size' => ModalAjaxMultiple::SIZE_LARGE,
                                    'toggleButton' => [
                                        'label' => '余额信息',
                                        'class' => 'btn btn-xs btn-primary'
                                    ],
                                    'url' => Url::to(['/ajax/plat/custom-money-inquiry', 'custom_id' => $custom->id]), // Ajax view with form to load
                                    'ajaxSubmit' => true, // Submit the contained form as ajax, true by default
                                    'options' => ['class' => 'header-primary'],
                                    'autoClose' => true,
                                ]);
                                $html = $modalA;
                                return $html;
                            },
                        ],
                        [
                            'label' => "其他",
                            'value' => function ()use($custom){
                                $html = Html::a("修改交易密码", ['/user/center/update-pay-password', 'custom_id' => $custom->id], ['class' => "btn btn-xs btn-danger"]);
                                return $html;
                            },
                            'format' => "raw",
                        ],
                    ],
                ]) ?>
            <?php else: ?>
                <p class="text-bold">
                    你没有绑定分账通客户
                </p>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php JsBlock::begin(); ?>
    <script>
        $(function (){});
        let App = new Vue({
            el: "#app",
            data: {
                xxx: "teest"
            },
            method: {
                test: function () {
                    alert(1);
                }
            }
        });
    </script>
<?php JsBlock::end(); ?>